package model.backup.handlers;

import database.Database;
import java.sql.SQLException;
import model.Address;
import model.backup.BackupAddress;

/**
 * Denne klasse bruges til at hente al data i bs_address og returnere det
 * @author junjie
 */
public abstract class BackupAddressHandler {
    /**
     * Henter alle rækker i bs_address og returnerer et BackupAddress[] model
     * @return BackupAddress[]
     * @throws ClassNotFoundException
     * @throws SQLException 
     */
    public static BackupAddress[] getAddress() throws ClassNotFoundException, SQLException{
        BackupAddress[] addressArray = null;
        
        Database db = new Database();
        
        String[][] result = db.getFromDB("bs_address", "", "", "", "id", "street", "zip_code");
        addressArray = new BackupAddress[result.length];
        
        db.closeDB();
        
        for(int i = 0; i< result.length; i++){
            addressArray[i] = new BackupAddress(Integer.parseInt(result[i][0]),result[i][1],result[i][2]);
        }
        return addressArray;
    }
}
